<template>
  <section class="group-list">
    <Tabs value="name1">
      <TabPane label="项目" name="name1"><div class="inner">
        <div class="draw-back">
          <Form :model="formItem" label-position="right" :label-width="80">
            <FormItem label="一级分类：">
              <Select v-model="formItem.pro" style="width:200px" @on-change="selpro">
                <Option v-for="item in proList" :value="item.id" :key="item.id" >{{ item.name }}</Option>
              </Select>
            </FormItem>
            <FormItem label="二级分类：">
              <Select v-model="formItem.city" style="width:200px" @on-change="selcity">
                <Option v-for="item in cityList" :value="item.id" :key="item.id" >{{ item.name }}</Option>
              </Select>
            </FormItem>
            <FormItem label="项目名称：">
              <Select v-model="formItem.dis" style="width:200px">
                <Option v-for="item in disList" :value="item.id" :key="item.id" >{{ item.name }}</Option>
              </Select>
            </FormItem>
            <FormItem label="服务项目：">
              <div v-for="(v,i) in list">
                <Input v-model="list[i]" placeholder="光子/嫩肤/补水"></Input>
                <div class="ico-add" @click="add"><Icon type="ios-add-circle-outline" /></div>
              </div>
            </FormItem>
            <FormItem label="预付金：">
              <Input v-model="formItem.yprice"></Input>
            </FormItem>
            <FormItem label="到院再付：">
              <Input v-model="formItem.zprice"></Input>
            </FormItem>
            <FormItem label="原价：">
              <Input v-model="formItem.price"></Input>
            </FormItem>
            <FormItem label="现价：">
              <Input v-model="formItem.nowprice"></Input>
            </FormItem>
            <FormItem label="折扣：">
              <Input v-model="formItem.sale"></Input>
            </FormItem>
            <FormItem label="医院：">
              <Input v-model="formItem.hospital"></Input>
            </FormItem>
            <FormItem label="医生：">
              <Input v-model="formItem.doctor"></Input>
            </FormItem>
            <FormItem label="特权专享:">
              <em>支付分期&nbsp;:</em>
                <RadioGroup v-model="formItem.radio">
                  <Radio label="0" >是</Radio>
                  <Radio label="1" >否</Radio>
                </RadioGroup>
                <em>红包抵扣&nbsp;:</em>
                <RadioGroup v-model="formItem.radio">
                  <Radio label="2">是</Radio>
                  <Radio label="3">否</Radio>
                </RadioGroup>
            </FormItem>

            <FormItem label="购买须知：">
              <Input v-model="formItem.notice" type="textarea" :rows="4" placeholder="请输入..." />
            </FormItem>

            <FormItem label="项目主图：">
                <el-upload
                        :action="UploadUrl()"
                        list-type="picture-card"
                        :on-success="handleRemove"
                        :class="{disabled:uploadDisabled}"
                        :limit="4">
                    <i class="el-icon-plus"></i>
                </el-upload>
            </FormItem>
            <FormItem label="项目详情：">
              <Input v-model="formItem.content" type="textarea" :rows="4" placeholder="" />
            </FormItem>
            <Checkbox  style="float: left;margin: 6px -8px 0 3px" v-model="single" ></Checkbox >
            <FormItem label="日记返现：">
              <Input v-model="formItem.moneytext" placeholder="日记阴影返现500元"></Input>
              <p> <span style="color: #FE5371;font-size: 12px">商业用户专享!</span></p>
            </FormItem>
          </Form>
        </div>
        <div style="padding-left: 70px;">
          <Button type="primary" size="large" style="width: 100px" @click="subimt">发布</Button>
        </div>
      </div></TabPane>
      <TabPane label="产品" name="name2"><div class="inner">
        <div class="draw-back">
          <Form :model="formItem" label-position="right" :label-width="80">
            <FormItem label="商品名称：">
              <Input v-model="formItem.alipay"></Input>
            </FormItem>
            <FormItem label="商品类别：">
              <!--<Input v-model="formItem.class"></Input>-->
              <Select v-model="formItem.pro" style="width:290px" @on-change="selpro">
                <Option v-for="item in proList" :value="item.id" :key="item.id" >{{ item.name }}</Option>
              </Select>
            </FormItem>
            <FormItem label="品牌：">
              <Input v-model="formItem.pai"></Input>
            </FormItem>
            <FormItem label="商品数量：">
              <Input v-model="formItem.num"></Input>
            </FormItem>
            <FormItem label="采购地：">
              <RadioGroup v-model="formItem.radio">
                <Radio label="1">国内</Radio>
                <Radio label="2">海外及港澳台</Radio>
              </RadioGroup>
            </FormItem>
            <FormItem label="商家编码：">
              <Input v-model="formItem.pianma"></Input>
            </FormItem>
            <FormItem label="商家地址：">
              <Input v-model="formItem.adress"></Input>
            </FormItem>
            <FormItem label="生产厂家：">
              <Input v-model="formItem.shengchan"></Input>
            </FormItem>
            <FormItem label="现价：">
              <Input v-model="formItem.price"></Input>
            </FormItem>
            <FormItem label="折扣：">
              <Input v-model="formItem.sale"></Input>
            </FormItem>
            <FormItem label="商品卖点：">
              <Input v-model="formItem.detail" type="textarea" :rows="4" placeholder="请输入..." />
            </FormItem>
              <FormItem label="上传图片：">
                  <el-upload
                          :action="UploadUrl()"
                          list-type="picture-card"
                          :on-success="handleRemove"
                          :class="{disabled:uploadDisabled}"
                          :limit="4">
                      <i class="el-icon-plus"></i>
                  </el-upload>
              </FormItem>
          </Form>
        </div>
        <div style="padding-left: 70px;">
          <Button type="primary" size="large" style="width: 100px" @click="subimt1">发布</Button>
        </div>
      </div>
      </TabPane>
    </Tabs>

  </section>
</template>

<script>

export default {
  name: 'ProjectList',
  components: {

  },
   data () {
      return {
          single:false,
          formItem: {},
          proList: [],
          cityList: [],
          disList: [],
          model1: '',
          pid:0,
          city:1,
          dis:2,
          list: [
              ''
          ],
          images:[],
          listid:'',
          img:'',
          uploadDisabled:false
      }
   },
    created () {
        // this.init()
        this.adrass()
        this.diss()
        this.citys()
    },
    computed: {

    },
    methods: {
        UploadUrl(){
            return  this.$Url+'/api/common/upload';
        },
        handleRemove (res) {
            console.log(res)
            this.images.push(res.data.url)
            console.log(this.images)
            if(this.images.length == 4){
                this.uploadDisabled = true
            }
        },
        add() {
            this.list.push('')
        },
        subimt () {
             this.formItem.ismoney = this.single ? 1:2;
             this.listid = this.list.join(',')
             this.img = this.images.join(',')
              let _this =this
            this.$post('/api/project/add_project',
                {
                    token:_this.$token,
                    group_id:_this.dis,
                    yprice:_this.formItem.yprice,
                    zprice:_this.formItem.zprice,
                    price:_this.formItem.price,
                    nowprice:_this.formItem.nowprice,
                    sale:_this.formItem.sale,
                    hospital:_this.formItem.hospital,
                    doctor:_this.formItem.doctor,
                    notice:_this.formItem.notice,
                    content:_this.formItem.content,
                    moneytext:_this.formItem.moneytext,
                    ismoney:_this.formItem.ismoney,
                    images:_this.img,
                    name:_this.listid,
                }, function (res) {
                    _this.$message({
                        message: res.msg,
                        type: 'success'
                    });
                   _this.$router.push({path:'/my/project/navlist'})
                }, function (errcode, errmsg,err) {
                    // console.log(err)
                    console.log(errmsg)

                })
        },
        adrass () {
            let _this =this
            this.$post('/api/project/project_type',
                {
                    pid:_this.pid,
                }, function (res) {
                    _this.proList = res.data
                }, function (errcode, errmsg,err) {
                    console.log(err)
                    console.log(errmsg)
                })
        },
        diss () {
            let _this =this
            this.$post('/api/project/project_type',
                {
                    pid:_this.dis,
                }, function (res) {
                    _this.disList = res.data
                }, function (errcode, errmsg,err) {
                    console.log(err)
                    console.log(errmsg)
                })
        },
        citys () {
            let _this =this
            this.$post('/api/project/project_type',
                {
                    pid:_this.city,
                }, function (res) {
                    _this.cityList = res.data
                }, function (errcode, errmsg,err) {
                    console.log(err)
                    console.log(errmsg)
                })
        },
        selpro (value) {
            this.city = value
            console.log(value)
            this.citys()
        },
        selcity (value) {
            console.log(value)
            this.dis = value
            this.diss()
        },
        subimt1 () {
            // this.listid = this.list.join(',')
            this.img = this.images.join(',')
            let _this =this
            this.$post('/api/goods/add_goods',
                {
                    token:_this.$token,
                    group_id:_this.pid,
                    name:_this.formItem.alipay,
                    brand:_this.formItem.pai,
                    num:_this.formItem.num,
                    place:_this.formItem.radio,
                    code:_this.formItem.pianma,
                    address:_this.formItem.adress,
                    factory:_this.formItem.shengchan,
                    nowprice:_this.formItem.price,
                    sale:_this.formItem.sale,
                    notice:_this.formItem.detail,
                    images:_this.img
                }, function (res) {
                    _this.$message({
                        message: res.msg,
                        type: 'success'
                    });
                    _this.$router.push({path:'/my/project/productlist'})
                }, function (errcode, errmsg,err) {
                    // console.log(err)
                    console.log(errmsg)

                })
        },
    }
}

</script>

<style lang="less" >
  @import "../../../style/style.less";
  .disabled .el-upload--picture-card {
      display: none;
  }
  .ivu-input-wrapper[data-v-0cf3f6cd]{
    width: 287px;
    margin: 6px 0;
  }
  .ico-add{
    float: right;
    margin: 3px 130px 0 0px;
    font-size: 25px;
  }
  .group-list {
    border: 1px solid @border-color;
    padding: 15px !important;
      .disabled .el-upload--picture-card {
          display: none;
      }
      .ivu-input-wrapper[data-v-0cf3f6cd]{
          width: 287px;
          margin: 6px 0;
      }
      .ico-add{
          float: right;
          margin: 3px -33px 0 0px;
          font-size: 25px;
      }
    >:first-child{
      color: #333333;
      font-size: 18px;
      padding-bottom: 15px;
      >span{
        font-size: 18px;
        color: @theme-color-dark;
        margin-left: 20px;
      }
    }
    .inner {
      padding-top: 15px;
    }
    .draw-back {
      width: 535px;
    }
    .tips {
      color: #333;
      font-size: 16px;
      font-weight: bold;
    }
    .selected-box {
      padding: 10px 0;
      margin-bottom: 20px;
      .item {
        color: @theme-color-dark;
        background-color: @theme-color-light;
        font-size: 14px;
        height: 28px;
        line-height: 28px;
        display: inline-block;
        margin: 14px 18px 0 0;
        border-radius: 4px;
        padding: 0 10px;
        cursor: pointer;
      }
      .active {
        background-color: @theme-color-dark;
        color: #fff;
      }
    }
  }
</style>
